package router

import (
	_ "gin_gorm_oj/docs"
	"gin_gorm_oj/middlewares"
	"gin_gorm_oj/service"
	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func Router() *gin.Engine {
	router := gin.Default()

	//swagger配置
	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
	// 路由
	//问题
	router.GET("/problemList", service.GetProblemList)
	router.GET("/problemDetail", service.GetProblemDetail)
	//用户
	router.GET("/userDetail", service.GetUserDetail)
	router.POST("/login", service.Login)
	router.POST("/sendEmail", service.SendEmail)
	router.POST("/register", service.Register)
	router.GET("/rankList", service.GetRankList)
	//提交记录
	router.GET("/submitList", service.GetSubmitList)

	//私有方法
	authAdmin := router.Group("/admin", middlewares.AuthAdmin())
	//创建问题
	authAdmin.POST("/createProblem", service.CreateProblem)
	//更新问题
	authAdmin.PUT("/updateProblem", service.UpdateProblem)
	//分类列表
	authAdmin.GET("/categoryList", service.GetCategoryList)
	//分类创建
	authAdmin.POST("/createCategory", service.CreateCategory)
	//分类更新
	authAdmin.POST("/updateCategory", service.UpdateCategory)
	//分类删除
	authAdmin.DELETE("/deleteCategory", service.DeleteCategory)

	//用户私有方法
	authUser := router.Group("/user", middlewares.AuthUserCheck())
	//代码提交
	authUser.POST("/submit", service.Submit)
	return router
}
